package Servlet;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class UserDaoTmpl implements UserDao {
    @Override
    public User login(User user) {
        Connection conn=null;
        PreparedStatement pstmt=null;
        ResultSet rs=null;
        //获取连接对象
        try {
            conn=JDBCutil.getConnection();
       //获取执行SQL的对象
            String sql="select * from user where username = ? and password =?";
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1, user.getUsername());
            pstmt.setString(2, user.getPassword());
            rs=pstmt.executeQuery();
            if (rs.next()){
                return user;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            JDBCutil.close(rs,pstmt,conn);
        }
        return null;
    }



}
